import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/assessments.dart';
import 'package:ichinesereader/models/assessment/assessmentBookType.dart';

class AssessmentBookTypeDropDown extends StatelessWidget {
  AssessmentBookTypeDropDown({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final AssessmentsController _assessmentcontroller = Get.find();
    AssessmentBookType currentType;
    if (_assessmentcontroller.currentAssessmentBookType.value.assessmentType ==
        null) {
      currentType = Constants.assessmentBookTypes[0];
    } else {
      currentType = _assessmentcontroller.currentAssessmentBookType.value;
    }

    return Container(
      width: 250,
      height: 80,
      child: DropdownButtonFormField(
          isExpanded: true,
          value: currentType,
          decoration: InputDecoration(
            labelText: 'Assessment Type'.tr,
          ),
          items: Constants.assessmentBookTypes
              .map((assessment) => DropdownMenuItem(
                    value: assessment,
                    child: Text(
                      '${assessment.displayName}',
                      style: Theme.of(context).textTheme.titleSmall,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ))
              .toList(),
          onChanged: (value) {
            var item = value as AssessmentBookType;
            if (item.assessmentType != null) {
              currentType = item;
              _assessmentcontroller.clearSelectedBenchmarkBookItems();
              _assessmentcontroller.setCurrentAssessmenbBookType(item);
              _assessmentcontroller.fetchAssessmentBenchmarkBooks(
                  '0', '0', item.assessmentType, '');
            }
          }),
    );
  }
}
